import { login } from '@/api/auth';
import { actions } from '@/store';
import { Button, Input } from 'antd';
import { useDispatch } from 'react-redux';
import { useNavigate, useSearchParams } from 'react-router-dom';

export default function Login() {
  const dispatch = useDispatch();
  const navigate = useNavigate();
  const [params] = useSearchParams();
  const nextPath = `/${params.get('redirect') || ''}`;
  const loginHandle = () => {
    login({
      username: '123',
      password: '123'
    }).then((res) => {
      dispatch(actions.auth.setToken(res));
      navigate(nextPath);
    });
  };
  return (
    <div>
      <Input placeholder="Basic usage" />
      <Input placeholder="Basic usage" />
      <Button onClick={loginHandle}>登录</Button>
    </div>
  );
}
